package com.idbk.chargestation.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

/**
 * 发表评论后 服务器返回的结果
 * @author lupc
 *
 */
public class JsonCommentResult extends JsonBase  {

	@SerializedName("commentItem")
	public JsonCommentResultInfo info;

	public static class JsonCommentResultInfo implements Parcelable {

		public final static String KEY = "JsonCommentResult";
		
		@SerializedName("id")
		public int id;

		@SerializedName("userId")
		public int userId;//用户id

		@SerializedName("name")
		public String name;//用户名称

		@SerializedName("imageURL")
		public String imageURL;//用户头像地址

		@SerializedName("commentDate")
		public Date commentDate;//评论时间

		@SerializedName("replyCount")
		public int replyCount;//回复总数

		@SerializedName("praiseFlag")
		public boolean praiseFlag;

		public String comment;//评论内容

		public int mark;//评分

		/**
		 * 评论发表的图片列表
		 */
		@SerializedName("commentImageURLs")
		public List<String> commentImageURLs;

		/**
		 * 用户已经通过的车主认证 的车标 url地址<br/>
		 * 注意：该值可能为空
		 */
		@SerializedName("ownerImageURLs")
		public List<String> carLogos;

		/**
		 * 将回复结果转换为 评论数据模型
		 * @return
		 */
		public JsonComment toJsonComment(){
			JsonComment jc = new JsonComment();
			jc.id = id;
			jc.userId = userId;
			jc.setName(name);
			jc.imageURL = imageURL;
			jc.commentDate = commentDate;
			jc.replyCount = replyCount;
			jc.praiseFlag = praiseFlag;

			//这2个量 服务器没有返回，直接从本地获取
			jc.comment = comment;
			jc.mark = mark;

			//评论发表的图片列表
			if(commentImageURLs != null){
				jc.commentImageURLs = new ArrayList<String>(commentImageURLs.size());
				jc.commentImageURLs.addAll(commentImageURLs);
			} else {
				jc.commentImageURLs = null;
			}
			//评论人 的车标
			if(carLogos != null){
				jc.carLogos = new ArrayList<String>(carLogos.size());
				jc.carLogos.addAll(carLogos);
			} else {
				jc.carLogos = null;
			}

			//补足一些数据
			jc.replys = null;

			return jc;
		}

		@Override
		public int describeContents() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public void writeToParcel(Parcel dest, int flags) {
			dest.writeInt(id);
			dest.writeInt(userId);

			dest.writeString(name);
			dest.writeString(imageURL);

			dest.writeLong(commentDate.getTime());
			dest.writeInt(replyCount);
			dest.writeInt(praiseFlag ? 1:0);	

			dest.writeString(comment);
			dest.writeInt(mark);

			//评论发表的图片列表		
			if(commentImageURLs != null){
				dest.writeStringList(commentImageURLs);
			} else {
				commentImageURLs = new ArrayList<String>();
				dest.writeStringList(commentImageURLs);
			}
			//评论人 的车标
			if(carLogos != null){
				dest.writeStringList(carLogos);
			} else {
				carLogos = new ArrayList<String>();
				dest.writeStringList(carLogos);
			}

		}

		public final static Parcelable.Creator<JsonCommentResultInfo> CREATOR = new Creator<JsonCommentResultInfo>() {

			@Override
			public JsonCommentResultInfo[] newArray(int size) {
				// TODO Auto-generated method stub
				return new JsonCommentResultInfo[size];
			}

			@Override
			public JsonCommentResultInfo createFromParcel(Parcel source) {
				// TODO Auto-generated method stub
				return new JsonCommentResultInfo(source);
			}
		}; 

		public JsonCommentResultInfo(Parcel source){
			id = source.readInt();
			userId = source.readInt();

			name = source.readString();
			imageURL = source.readString();

			commentDate = new Date(source.readLong());	
			replyCount = source.readInt();
			praiseFlag = source.readInt() == 1? true:false;

			comment = source.readString();
			mark = source.readInt();

			//评论发表的图片列表	
			commentImageURLs = new ArrayList<String>();
			source.readStringList(commentImageURLs);		
			//评论人 的车标
			carLogos = new ArrayList<String>();
			source.readStringList(carLogos);		
		}

		public JsonCommentResultInfo(){

		}
	}

}
